#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
string s;
void add(char a, char b, char c, int cnt) {  // add b, c cnt
  if (!cnt) return;
  int pos = 0;
  int n = s.size();
  rep(i, 0, n - 1) {
    if (s[i] == a && s[i + 1] != a || s[i] != a && s[i + 1] == a) {
      pos = i;
      break;
    }
  }
  char first = a + b + c - (s[pos] + s[pos + 1]);
  char second = b + c - first;
  rep(i, 1, cnt) {
    cout << pos + 1 << endl;
    s.insert(pos + 1, 1, first);
    if (s[pos] != a) pos++;
    cout << pos + 1 << endl;
    s.insert(pos + 1, 1, second);
    if (s[pos] != a) pos++;
  }
}
void output(char cmx, char cmid, char cmn, int mx, int mid, int mn) {
  add(cmid, cmx, cmn, mid - mn);
  add(cmx, cmid, cmn, mx - mn);
}
void solve() {
  cin >> n >> s;
  int a = 0, b = 0, c = 0;
  rep(i, 0, n - 1) {
    if (s[i] == 'T')
      a++;
    else if (s[i] == 'I')
      b++;
    else
      c++;
  }
  if (a == n || b == n || c == n) {
    cout << -1 << endl;
    return;
  }
  if (a == b && b == c) {
    cout << 0 << endl;
    return;
  }
  int mn = min({a, b, c});
  int mx = max({a, b, c});
  int mid = a + b + c - mn - mx;
  int cnt = (mid - mn) * 2 + (mx - mn) * 2;
  cout << cnt << endl;
  char cmx, cmid, cmn;
  if (mx == a) {
    if (mid == b)
      output('T', 'I', 'L', a, b, c);
    else
      output('T', 'L', 'I', a, c, b);
  } else if (mx == b) {
    if (mid == a)
      output('I', 'T', 'L', b, a, c);
    else
      output('I', 'L', 'T', b, c, a);
  } else {
    if (mid == a)
      output('L', 'T', 'I', c, a, b);
    else
      output('L', 'I', 'T', c, b, a);
  }
  // cout << s << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}